package HomeWork.msg.service;

import HomeWork.msg.domain.CheckCode;

import java.util.ArrayList;
import java.util.Random;

public abstract class SendMsg {
    private CheckCode checkCode;
    protected ArrayList<CheckCode> list = new ArrayList<CheckCode>();
    public void sendMsg(String phone){
        list.add(new CheckCode(phone,code()));
        System.out.println("访问" + getName() + "短信平台给" + phone + "发送短信验证码:" + code());
    }

    protected abstract String getName();

    protected String code(){
        // 补全代码
        //随机从chs数组中取字符,拼接字符串, -- 循环4次 ,返回
        StringBuilder sb = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < 4; i++) {

            sb.append(random.nextInt(10));
        }
        return sb.toString();
    }
}
